package org.chris.quick.b.activities;

import android.content.Context;
import android.content.Intent;
import android.webkit.WebSettings;
import android.webkit.WebView;


import org.chris.quick.R;

/**
 * @author Chris zou
 * @Date 2016/11/3
 * @modifyInfo1 Zuo-2016/11/3
 * @modifyContent
 */

public class WebActivity extends ThemeActivity {

    private WebView mWebView;
    private String url;

    @Override
    public void init() {
        setBackValid(R.mipmap.ic_close_white_24dp);
        url = getIntent().getStringExtra("url");
        onInitLayout();
        onBindData();
    }

    @Override
    public int onResultLayoutResId() {
        return R.layout.activity_web;
    }

    public void onInitLayout() {
        mWebView = (WebView) findViewById(R.id.webContent);
        // 设置可以支持缩放
        mWebView.getSettings().setSupportZoom(true);
        // 设置出现缩放工具
        mWebView.getSettings().setBuiltInZoomControls(true);
        //扩大比例的缩放
        mWebView.getSettings().setUseWideViewPort(true);
        //自适应屏幕
        mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.getSettings().setJavaScriptEnabled(true);

    }

    public void onBindData() {
        mWebView.loadUrl(url);
    }

    @Override
    public void onBackPressed() {
        if (mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    public static void startAction(Context context, String title, String url) {
        Intent intent = new Intent(context, WebActivity.class);
        intent.putExtra(ThemeActivity.TITLE, title);
        intent.putExtra("url", url);
        context.startActivity(intent);
    }
}
